﻿using System;
using Axiom;
using Axiom.Core;
using Axiom.Math;
using Axiom.Graphics;
using Axiom.ParticleSystems;
using Axiom.ParticleFX;
using System.Collections.Generic;


namespace ExampleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            BasicTutorial1 app = new BasicTutorial1();
            app.Run();
        }
    }

    public class BasicTutorial1 : ExampleApplication
    {

        ParticleSystem particleSystem_;
        DateTime time_ = new DateTime();
        SceneNode cubeNode_;



        protected override void CreateScene()
        {
            SceneManager.AmbientLight = new ColorEx(1, 1, 1);
            Camera.Position = new Vector3(0, 0, 0);
            Camera.Orientation = Quaternion.Identity;



            //TriangulationAndSetPartition(ent2.Mesh);

            particleSystem_ = (ParticleSystem)ParticleSystemManager.Instance.CreateSystem("", 100);
            // particleSystem_.MaterialName = "Particles/Flare";

            SceneNode partNode = SceneManager.RootSceneNode.CreateChildSceneNode();
            partNode.Position = new Vector3(0, 0, 0);
            partNode.AttachObject(particleSystem_);



            Entity dragonMesh = SceneManager.CreateEntity("MayaCube", "dragon.mesh");
            //  Entity CubeMesh = SceneManager.CreateEntity("MayaCube", "MayaCube.mesh");
            SceneNode dragonNode = SceneManager.RootSceneNode.CreateChildSceneNode("dragonNode", new Vector3(0, -3, 0));
            dragonNode.AttachObject(dragonMesh);

            Entity cube = SceneManager.CreateEntity("Cube", "MayaCube.mesh");
            cubeNode_ = SceneManager.RootSceneNode.CreateChildSceneNode("CubeNode");
            cubeNode_.AttachObject(cube);


        }

        double ticks = 0;
        int timer = 0;

        protected override void FrameStarted(object source, FrameEventArgs e)
        {
            
            timer++;
            base.FrameStarted(source, e);
            if (timer % 5 == 0)
            {
                ticks += Math.PI / 180.0;
                //long ticks = DateTime.Now.Ticks;
                float scale = 8.0f;

                Vector3 delta = new Vector3(
                    (float)(scale * (Math.Sin(ticks) - cubeNode_.Position.x / scale)),
                    (float)(scale * (Math.Cos(ticks) - cubeNode_.Position.y / scale)),// (float)Math.Sin(ticks) - cubeNode_.Position.x,
                    -0.05f);

                cubeNode_.Translate(delta);

                //cubeNode_.Translate( new Vector3(1.0f, 0, 0) );
            }
        }
    }

}